//
//  CarDescriptionCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/15/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit
import SnapKit

final class CarDescriptionCell: UITableViewCell {

    // MARK: - Outlets

    private lazy var titleLbl: UILabel = {
        let lbl = UILabel()
        lbl.font = UIFont.systemFont(ofSize: 17, weight: .bold)
        lbl.textAlignment = .left
        lbl.sizeToFit()
        lbl.textColor = .black
        lbl.text = "Описание"
        return lbl
    }()
    
    private lazy var fullText: UILabel = {
        let lbl = UILabel()
        lbl.font = UIFont.systemFont(ofSize: 15, weight: .medium)
        lbl.textColor = .darkBlueColor
        lbl.numberOfLines = 0
        lbl.sizeToFit()
        lbl.textColor = .black
        return lbl
    }()
    
    private lazy var separatorView = CellSeparator()
    
    
    // MARK: - Init
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addViews()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension CarDescriptionCell: ConfigurableCell {
    func configure(data object: String?, index: Int) {
        self.fullText.text = object ?? ""
    }

    func returnData() -> String? {
        return nil
    }
}



extension CarDescriptionCell {
    
    private func addViews () {
        self.contentView.addSubview(titleLbl)
        self.contentView.addSubview(fullText)
        self.contentView.addSubview(separatorView)
        
        titleLbl.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview().inset(16)
            make.top.equalToSuperview().offset(22)
            make.height.equalTo(20)
        }
        
        separatorView.snp.makeConstraints { (make) in
            make.leading.trailing.bottom.equalToSuperview()
        }
        
        fullText.snp.makeConstraints { (make) in
            make.top.equalTo(titleLbl.snp.bottom).offset(18)
            make.leading.trailing.equalToSuperview().inset(16)
            make.bottom.equalTo(separatorView.snp.top).offset(-20)
        }
    }
}
